/**
 * 
 */
package com.feonix.designPattern.Iterator.sample;

import java.util.ArrayList;
import java.util.List;

/**
 * @CopyRight (c)1993-2017
 * @Project common_practice
 * @Comments 请输入该类的描述
 * @NameSpace com.feonix.designPattern.Iterator.sample
 * @Author Feonixzw
 * @CreateDate 2018年1月24日
 */
public class BookShelf implements Aggregate{
	
	private List<Book> books;
	
	private int last = 0;
	
	public BookShelf(){
		this.books = new ArrayList<Book>();
	}
	
	public Book getBookAt(int index){
		return books.get(index);
	}
	
	public void appendBook(Book book){
		books.add(last, book);
		this.last++;
	}
	
	public int getLength(){
		return this.last;
	}

	/* (non-Javadoc)
	 * @see com.feonix.designPattern.Iterator.sample.Aggregate#iterator()
	 */
	@Override
	public Iterator iterator() {
		return new BookShelfIterator(this);
	}

}
